Skip to content

Make Sprocket the source of truth for org-team permissions (#726)#738

Open
gankoji wants to merge 3 commits intomainfrom
cursor/issue-726-org-team-permissions-9d08
Open

Make Sprocket the source of truth for org-team permissions (#726)#738
gankoji wants to merge 3 commits intomainfrom
cursor/issue-726-org-team-permissions-9d08

Conversation

@gankoji
Copy link
Copy Markdown
Member

@gankoji gankoji commented Apr 13, 2026

Summary

Implements GitHub issue #726: org-team / LO-style permission bits used in JWTs and guards now persist in Sprocket (sprocket.user_org_team_permission) instead of reading mledb.player_to_org on every login/refresh.

What changed

  • New table sprocket.user_org_team_permission (migration 1770500000000-UserOrgTeamPermission) with unique (userId, orgTeam) and FK to sprocket.user.
  • UserOrgTeamPermissionService — list/replace/add/remove permissions.
  • OrgTeamPermissionResolutionService — resolves org teams for a user id; prefers Sprocket rows.
  • Login / refresh (OauthController) — builds orgTeams from resolution (no direct player_to_org reads).
  • loginAsUser — copies target user’s resolved org teams into the short-lived token.
  • ReplayParseService — LO/admin override uses resolution instead of MLEDB.
  • FormerPlayerScrimGuard — short-circuits for LO/admin via resolution; still uses MLE player for the FP check (guard is now a proper MledbInterfaceModule provider).
  • Admin GraphQL (MLEDB admin guard): userOrgTeamPermissions, setUserOrgTeamPermissions, addUserOrgTeamPermission, removeUserOrgTeamPermission.
  • Docs: reports/issue-726-org-team-permissions.md — source of truth, env flag, removal plan, Pulumi prod key, backfill SQL path.

Dual-read compatibility (temporary)

If a user has no Sprocket permission rows and ORG_TEAM_PERMISSION_DUAL_READ=true, resolution falls back to legacy mledb.player_to_org. Default is off in app code; prod Pulumi sets platform:org-team-permission-dual-read: "true" in infra/platform/Pulumi.prod.yaml until backfill is applied, then operators should set it to false and redeploy.

Core/monolith Docker services receive ORG_TEAM_PERMISSION_DUAL_READ from Pulumi config platform:org-team-permission-dual-read (infra/platform/src/Platform.ts).

Backfill

Run scripts/sql/backfill-user-org-team-permission-from-mledb.sql against prod Postgres (same DB with mledb + sprocket). Idempotent (ON CONFLICT DO NOTHING).

Proof

  • npm run build --workspace=core (passes).
  • npm exec -- tsc --noEmit -p tsconfig.json in infra/platform (passes).

Follow-ups (not in this PR)

  • After backfill + validation: set platform:org-team-permission-dual-read to false in prod stack, pulumi up, then remove the dual-read code path when MLEDB is gone.
Open in Web Open in Cursor 

cursoragent and others added 2 commits April 13, 2026 17:04
- Add sprocket.user_org_team_permission table and TypeORM entity
- Resolve JWT org teams from Sprocket; optional ORG_TEAM_PERMISSION_DUAL_READ MLEDB fallback
- Admin GraphQL CRUD for org-team permissions; wire loginAsUser and replay-parse override
- Register FormerPlayerScrimGuard in MledbInterfaceModule for DI
- Document source of truth and removal plan in reports/

Co-authored-by: Jake Bailey <asaxplayinghorse@gmail.com>
- Read platform:org-team-permission-dual-read and set ORG_TEAM_PERMISSION_DUAL_READ on core/monolith
- Enable dual-read in Pulumi.prod.yaml until MLEDB backfill completes
- Add SQL backfill script mledb.player_to_org -> sprocket.user_org_team_permission
- Document Pulumi key and script path in issue-726 report

Co-authored-by: Jake Bailey <asaxplayinghorse@gmail.com>
@gankoji gankoji marked this pull request as ready for review April 14, 2026 00:19
- When ORG_TEAM_PERMISSION_DUAL_READ=true, fetch player_to_org every time
- Log mismatches (warn vs verbose for pre-backfill empty Sprocket)
- Return semantics unchanged: prefer Sprocket rows, else MLEDB under dual-read
- Update issue-726 ops doc for dual-read behavior

Co-authored-by: Jake Bailey <asaxplayinghorse@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants